package com.hanbang.qzzds.pressenter.home;

import com.hanbang.qzzds.appliction.base.presenter.BasePresenter;
import com.hanbang.qzzds.mode.HttpRequest;
import com.hanbang.qzzds.mode.httpresponse.HttpResult;
import com.hanbang.qzzds.mode.javabean.base.UserData;
import com.hanbang.qzzds.utils.http.HttpCallBack;
import com.hanbang.qzzds.view.home.iview.IHomeView;

import java.util.List;

import static android.R.attr.order;

/**
 * 作者　　: 李坤
 * 创建时间:2016/9/19　17:05
 * 邮箱　　：496546144@qq.com
 * <p>
 * 功能介绍：
 */

public class HomePresenter extends BasePresenter<IHomeView> {


    public void getHttpData(final boolean isStart) {
        if (isStart) {
            mvpView.clearPagingData();
        }
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this)
                .setShowLoadding(order == -1 ? false : true)
                .setLoadingAndRetryManager(mvpView.getLoadingAndRetryManager())
                .setStatusChangListener(mvpView.getStatusChangListener())
                .setSwipeRefreshLayout(mvpView.getSwipeRefreshLayout());

        final HttpCallBack httpCallBack = new HttpCallBack<HttpResult<List<UserData>>>(buider) {
            @Override
            public void onNext(HttpResult<List<UserData>> result) {
                super.onNext(result);
                //进行data处理
                if (result.isSucceed()) {
                    if (isStart) {
                        mvpView.clearData();
                    }
                    // result.dongtaiList = (List<XiuChangItemData>) mvpView.getValidData(result.getDongtaiList());
                    mvpView.upDataUI();
                }
            }
        };
        mvpView.addSubscription(HttpRequest.GetArticleList(httpCallBack, mvpView.getPageindex(), mvpView.getPageCount(), 1, 23, 4));
    }
}
